home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / Pascal Demos / MultiSkel / MSkelHelp.p < prev    next >
Encoding:
Text File  |  1994-02-23  |  4.8 KB  |  211 lines  |  [TEXT/PJMM]

  1. unit MultiSkelHelp;
  2.  
  3. interface
  4.  
  5.     uses
  6.         TransSkel, MultiSkelGlobals;
  7.  
  8.     procedure HelpWindInit;
  9.  
  10. implementation
  11.  
  12.     var
  13.  
  14.         teHelp: TEHandle;
  15.         helpScroll: ControlHandle;
  16.         helpLine: Integer;
  17.         halfPage: Integer;
  18.  
  19.  
  20.     procedure DoScroll (lDelta: Integer);
  21.         var
  22.             newLine: Integer;
  23.     begin
  24.         newLine := helpLine + lDelta;
  25.         if (newLine < 0) then
  26.             newLine := 0;
  27.         if (newLine > GetCtlMax(helpScroll)) then
  28.             newLine := GetCtlMax(helpScroll);
  29.         SetCtlValue(helpScroll, newLine);
  30.         lDelta := (helpLine - newLine) * teHelp^^.lineHeight;
  31.         TEScroll(0, lDelta, teHelp);
  32.         helpLine := newLine;
  33.     end;
  34.  
  35.  
  36.     procedure TrackScroll (theScroll: ControlHandle;
  37.                                     partCode: Integer);
  38.         var
  39.             lDelta: Integer;
  40.     begin
  41.         if (partCode = GetCRefCon(theScroll)) then
  42.             begin
  43.                 case partCode of
  44.                     inUpButton: 
  45.                         lDelta := -1;
  46.                     inDownButton: 
  47.                         lDelta := 1;
  48.                     inPageUp: 
  49.                         lDelta := -halfPage;
  50.                     inPageDown: 
  51.                         lDelta := halfPage;
  52.                 end;
  53.                 DoScroll(lDelta);
  54.             end;
  55.     end;
  56.  
  57.  
  58.     procedure Mouse (pt: Point;
  59.                                     t: LongInt;
  60.                                     mods: Integer);
  61.         var
  62.             thePart: Integer;
  63.             ignore: Integer;
  64.     begin
  65.         thePart := TestControl(helpScroll, pt);
  66.         if (thePart = inThumb) then
  67.             begin
  68.                 ignore := TrackControl(helpScroll, pt, nil);
  69.                 DoScroll(GetCtlValue(helpScroll) - helpLine);
  70.             end
  71.         else if (thePart <> 0) then
  72.             begin
  73.                 SetCRefCon(helpScroll, thePart);
  74.                 ignore := TrackControl(helpScroll, pt, @TrackScroll);
  75.             end;
  76.     end;
  77.  
  78.  
  79.     procedure Update (resized: Boolean);
  80.         var
  81.             r: Rect;
  82.             visLines: Integer;
  83.             lHeight: Integer;
  84.             topLines: Integer;
  85.             nLines: Integer;
  86.             scrollLines: Integer;
  87.     begin
  88.         r := helpWind^.portRect;
  89.         EraseRect(r);
  90.         if (resized) then
  91.             begin
  92.                 r.left := r.left + 4;
  93.                 r.bottom := r.bottom - 2;
  94.                 r.top := r.top + 2;
  95.                 r.right := r.right - 19;
  96.                 teHelp^^.destRect.right := r.right;
  97.                 teHelp^^.viewRect := r;
  98.                 TECalText(teHelp);
  99.                 lHeight := teHelp^^.lineHeight;
  100.                 nLines := teHelp^^.nLines;
  101.                 visLines := (r.bottom - r.top) div lHeight;
  102.                 halfPage := visLines div 2;
  103.                 topLines := (r.top - teHelp^^.destRect.top) div lHeight;
  104.                 scrollLines := visLines - (nLines - topLines);
  105.                 if ((scrollLines > 0) and (topLines > 0)) then
  106.                     begin
  107.                         if (scrollLines > topLines) then
  108.                             scrollLines := topLines;
  109.                         TEScroll(0, scrollLines * lHeight, teHelp);
  110.                     end;
  111.                 scrollLines := nLines - visLines;
  112.                 helpLine := (r.top - teHelp^^.destRect.top) div lHeight;
  113.                 HideControl(helpScroll);
  114.                 r := helpWind^.portRect;
  115.                 r.left := r.right - 15;
  116.                 r.bottom := r.bottom - 14;
  117.                 r.top := r.top - 1;
  118.                 r.right := r.right + 1;
  119.                 SizeControl(helpScroll, r.right - r.left, r.bottom - r.top);
  120.                 MoveControl(helpScroll, r.left, r.top);
  121.                 if ((nLines - visLines) < 0) then
  122.                     SetCtlMax(helpScroll, 0)
  123.                 else
  124.                     SetCtlMax(helpScroll, nLines - visLines);
  125.                 SetCtlValue(helpScroll, helpLine);
  126.                 ShowControl(helpScroll);
  127.             end;
  128.         DrawGrowBox(helpWind);
  129.         DrawControls(helpWind);
  130.         r := teHelp^^.viewRect;
  131.         TEUpdate(r, teHelp);
  132.         ValidRect(helpWind^.portRect);
  133.     end;
  134.  
  135.  
  136.     procedure Activate (active: Boolean);
  137.     begin
  138.         DrawGrowBox(helpWind);
  139.         if (active) then
  140.             begin
  141.                 DisableItem(editMenu, 0);
  142.                 if (GetCtlMax(helpScroll) > 0) then
  143.                     HiliteControl(helpScroll, normalHilite)
  144.                 else
  145.                     HiliteControl(helpScroll, dimHilite);
  146.             end
  147.         else
  148.             begin
  149.                 EnableItem(editMenu, 0);
  150.                 if (GetCtlMax(helpScroll) > 0) then
  151.                     HiliteControl(helpScroll, dimHilite);
  152.             end;
  153.         DrawMenuBar;
  154.     end;
  155.  
  156.  
  157.     procedure Clobber;
  158.     begin
  159.         TEDispose(teHelp);
  160.         DisposeControl(helpScroll);
  161.         DisposeWindow(helpWind);
  162.     end;
  163.  
  164.  
  165.     procedure HelpWindInit;
  166.         var
  167.             r: Rect;
  168.             textHandle: Handle;
  169.             visLines: Integer;
  170.             scrollLines: Integer;
  171.             ignore: Boolean;
  172.     begin
  173.         if (SkelQuery(skelQHasColorQD) <> 0) then
  174.             helpWind := GetNewCWindow(helpWindRes, nil, WindowPtr(-1))
  175.         else
  176.             helpWind := GetNewWindow(helpWindRes, nil, WindowPtr(-1));
  177.         if (helpWind = nil) then
  178.             exit(HelpWindInit);
  179.         ignore := SkelWindow(helpWind, @Mouse, nil, @Update, @Activate, nil, @Clobber, nil, false);
  180.  
  181.         TextFont(0);
  182.         TextSize(0);
  183.  
  184.         r := helpWind^.portRect;
  185.         r.left := r.left + 4;
  186.         r.bottom := r.bottom - 2;
  187.         r.top := r.top + 2;
  188.         r.right := r.right - 19;
  189.         teHelp := TENew(r, r);
  190.         textHandle := GetResource('TEXT', helpTextRes);
  191.         HLock(textHandle);
  192.         TEInsert(textHandle^, GetHandleSize(textHandle), teHelp);
  193.         HUnlock(textHandle);
  194.         ReleaseResource(textHandle);
  195.  
  196.         visLines := (r.bottom - r.top) div teHelp^^.lineHeight;
  197.         scrollLines := teHelp^^.nLines - visLines;
  198.         halfPage := visLines div 2;
  199.         helpLine := 0;
  200.         r := helpWind^.portRect;
  201.         r.left := r.right - 15;
  202.         r.bottom := r.bottom - 14;
  203.         r.top := r.top - 1;
  204.         r.right := r.right + 1;
  205.  
  206.         helpScroll := NewControl(helpWind, r, '', true, helpLine, 0, scrollLines, scrollBarProc, 0);
  207.  
  208.         ValidRect(helpWind^.portRect);
  209.     end;
  210.  
  211. end.